<?php
	global $logid;
	$pageVars = array();
	$errmsg = GetMessageStack();
	$userDao = GetUserDAO();		

	//write to database
	if(isset($_POST['action'])) {
			$action=trim($_POST['action']);
			if( $action == 'crop_avatar' ) {
				
					$params['id'] = $logid;
		
					//save file operation
					$userBasicInfo = $userDao->GetUserBasicInfo( $logid);
					
					$x1 = intval($_POST['x1']);
					$y1 = intval($_POST['y1']);
					$w = intval($_POST['w']);
					$h = intval($_POST['h']);
				
				/************************
				 * delete by bo					
				 * $w and $h are the crop height and width. not the resize height and width.
				 ************************/
//                  
//					if( $w >= 80 || $h >= 80){
//						$w = 80;
//						$h = 80;
//					}
						
					$edpImg = GetEDPImage();
					$edpImg->CropAvatar( EdpGetAvatarPath($userBasicInfo['logo_path']), $x1, $y1, $w, $h );

					$errmsg->add( 'change_avatar', '更新成功', 'success' );
					
					ob_clean();
					edp_redirect_inner( 'user_setting', 'subpage=basic_info');
		
			} else {
				$errmsg->add( 'change_avatar', '未知操作', 'error' );
		}
	}
	
	
	$userBasicInfo = $userDao->GetUserBasicInfo( $logid);
	if( $userBasicInfo ){
		$pageVars['id'] = $userBasicInfo['id'];
		$pageVars['nick'] = $userBasicInfo['nick'];
		if( edp_is_empty_string($userBasicInfo['logo_path']) )
			$pageVars['avatarPath'] = DEFAULT_AVATAR_URL;
		else
			$pageVars['avatarPath'] = EdpGetOriAvatarUrl( $userBasicInfo['logo_path'] );
	}
	else{
		$errmsg->add( 'change_avatar', '读取用户信息失败', 'error' );
	}
?>